<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>就业意向</title>
    <link rel="shortcut icon" href="../../image/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="../../css/main.css" media="all">
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <div class="layui-container">
        <!--      就业意向   -->
        <div class="layui-card" style="margin-top: 15px">
            <div class="layui-card-header"><b style="font-size: 18px">就业意向</b>
                <span id="updatetime" style="margin-left: 30px;color: #4E5465">最后更新 <span>2020.11.20 15:04</span></span>
            </div>
            <div class="layui-card-body">
                <form class="layui-form" action="" lay-filter="formtest">
                    <!--  求职状态  -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">求职状态</label>
                        <div class="layui-input-block">
                            <select name="candidatestatus" lay-verify="required">
                                <option value=""></option>
                                <option value="离校-随时到岗">离校-随时到岗</option>
                                <option value="在校-月内到岗">在校-月内到岗</option>
                                <option value="在校-考虑机会">在校-考虑机会</option>
                                <option value="在校-暂不考虑">在校-暂不考虑</option>
                                <option value="已在职">已在职</option>
                            </select>
                        </div>
                    </div>
                    <!--     期望薪资  -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">期望薪资</label>
                        <div class="layui-input-block">
                            <select name="salaryexpectation" lay-verify="required">
                                <option value=""></option>
                                <option value="不限">不限</option>
                                <option value="3k以下">3k以下</option>
                                <option value="3k-5k">3k-5k</option>
                                <option value="5k-8k">5k-8k</option>
                                <option value="8k-10k">8k-10k</option>
                                <option value="10k-12k">10k-12k</option>
                                <option value="12k-15k">12k-15k</option>
                                <option value="15k-20k">15k-20k</option>
                                <option value="20k-30k">20k-30k</option>
                                <option value="30k-50k">30k-50k</option>
                                <option value="50k以上">50k以上</option>
                            </select>
                        </div>
                    </div>
                    <!--  工作地点     -->
                    <div class="layui-form-item">
                        <div class="layui-form-item" id="area-picker">
                            <div class="layui-form-label">工作地点</div>
                            <div class="layui-input-inline" style="width: 200px;">
                                <select name="province" class="province-selector"
                                        lay-filter="province-1">
                                    <option value="">请选择省</option>
                                </select>
                            </div>
                            <div class="layui-input-inline" style="width: 200px;">
                                <select name="city" class="city-selector" lay-filter="city-1">
                                    <option value="">请选择市</option>
                                </select>
                            </div>
                            <div class="layui-input-inline" style="width: 200px;">
                                <select name="county" class="county-selector"
                                        lay-filter="county-1">
                                    <option value="">请选择区</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <!--  期望行业       -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">期望行业</label>
                        <div class="layui-input-block">
                            <select name="jobtype" id="jobType" lay-verify="required">
                                <option value=""></option>
                                <option value="不限">不限</option>
                            </select>
                        </div>
                    </div>
                    <!--  学历要求    -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">学历要求</label>
                        <div class="layui-input-block">
                            <select name="educationrequirements" lay-verify="required">
                                <option value=""></option>
                                <option value="不限">不限</option>
                                <option value="初中及以下">初中及以下</option>
                                <option value="中专/中技">中专/中技</option>
                                <option value="高中">高中</option>
                                <option value="大专">大专</option>
                                <option value="本科">本科</option>
                                <option value="硕士">硕士</option>
                                <option value="博士">博士</option>
                            </select>
                        </div>
                    </div>
                    <!--   工作经验       -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">工作经验</label>
                        <div class="layui-input-block">
                            <select name="workingexperience" lay-verify="required">
                                <option value=""></option>
                                <option value="不限">不限</option>
                                <option value="在校生">在校生</option>
                                <option value="应届生">应届生</option>
                                <option value="1年以内">1年以内</option>
                                <option value="1-3年">1-3年</option>
                                <option value="3-5年">3-5年</option>
                                <option value="5-10年">5-10年</option>
                                <option value="10年以上">10年以上</option>
                            </select>
                        </div>
                    </div>
                    <!--  自我评价      -->
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">自我评价</label>
                        <div class="layui-input-block">
                                <textarea name="selfevaluation" lay-verify="required"
                                          placeholder="介绍自己，说明自己的最大优势，让企业看到你的闪光点"
                                          class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="formintention">提交
                            </button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

</div>

</body>
<script src="../../libs/layui/layui.js"></script>
<script src="../../js/model.js"></script>
<script>
    layui.use(['okLayer', 'form', 'layarea', 'jquery', 'okUtils'], function () {
        var okLayer = layui.okLayer;
        let form = layui.form;
        let layarea = layui.layarea;
        let $ = layui.jquery;
        let okUtils = layui.okUtils;
        // 获取contentText
        const ctx = function () {
            let pathName = document.location.pathname;
            let index = pathName.substr(1).indexOf("/");
            let result = pathName.substr(0, index + 1);
            return result;
        }();
        // 获取student
        var student = JSON.parse(window.sessionStorage.getItem("student"));
        var url = ctx + "/pages/student/studentLogin.html";
        if (student == null) {
            okLayer.yellowSighMsg("登陆时间超时，请重新登录！", function () {
                window.sessionStorage.clear();
                window.open(url, "_top", "", "true");
            });
        }

        loadingPostType();

        //加载岗位类型
        function loadingPostType() {
            $.ajax({
                url: ctx + "/ygssecs/getjobType",
                type: 'GET',
                dataType: 'JSON'
                // headers: {"token": sessionStorage.getItem("token")},
            }).done(function (datas) {
                var list = datas['data'];
                var option;
                for (var i = 0; i < list.length; i++) {
                    option += "<option value='" + list[i]['typename'] + "'>" + list[i]['typename'] + "</option>";//拼接option中的内容
                    //将option的拼接内容加入select中，注意选择器是select的ID
                }
                $("#jobType").append(option);
                form.render('select');//重点：重新渲染select
                requestEmploymentIntention();
            }).fail(function () {
                console.log("error");
            });
        }

        //请求就业意向数据
        function requestEmploymentIntention() {
            $.ajax({
                url: ctx + "/ygssecs/getintentionbystuid",
                type: 'GET',
                data: {stuid: student.stuid},
            }).done(function (response) {
                if (response.code == 200) {
                    document.getElementById('updatetime').innerText = "最后更新" + response.data.updatetime;
                    form.val('formtest', response.data)
                    let workplace = response.data.workplace;
                    var strs = workplace.split(",");
                    layarea.render({
                        elem: '#area-picker',
                        data: {
                            province: strs[0],
                            city: strs[1],
                            county: strs[2],
                        }
                    });
                } else if (response.code == 201) {
                    document.getElementById('updatetime').innerText = response.data;
                    layarea.render({
                        elem: '#area-picker',
                        data: {
                            province: '北京市',
                            city: '北京市',
                            county: '东城区',
                        }
                    });
                }
            }).fail(function () {
                parent.location.reload()
            })
        }

        //数据更新
        form.on('submit(formintention)', function (data) {
            var warkplace = data.field.province + "," + data.field.city + "," + data.field.county;
            var intention = new Intention(null, data.field.salaryexpectation, warkplace, data.field.educationrequirements, data.field.workingexperience, data.field.jobtype, data.field.candidatestatus, data.field.selfevaluation, null, student);
            okUtils.ajax("/ygssecs/updateIntention", "post", {intentionjson: JSON.stringify(intention)}, true).done(function (response) {
                okLayer.greenTickMsg(response.msg, function () {
                    location.reload();
                })
            }).fail(function (error) {
                console.log(error)
            });
            return false;
        });

    });
</script>
</html>